<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="/shop/include :: header"></head>
<body>
	<div class="layui-fluid">
		<table id="shop_member_address-table" lay-filter="shop_member_address-table"></table>
	</div>
	<!-- 工具栏 -->
	<script type="text/html" id="toolbarShopMemberAddress">
        <div class="layui-btn-container">
			<button shiro:hasPermission="shop:member_address:add" class="layui-btn layui-btn-sm" lay-event="add"><i class="layui-icon layui-icon-add-circle" ></i>添加</button>
            <button shiro:hasPermission="shop:member_address:batchRemove" class="layui-btn layui-btn-sm layui-btn-danger" lay-event="batchRemove"><i class="layui-icon layui-icon-delete"></i>删除</button>
        </div>
    </script>
	<!-- 操作列 -->
	<script type="text/html" id="shop_member_address-state">
     <div class="layui-btn-group">
        <button shiro:hasPermission="shop:member_address:edit" class="layui-btn layui-btn-sm" lay-event="edit"><i class="layui-icon layui-icon-edit"></i></button>
        <button shiro:hasPermission="shop:member_address:remove" class="layui-btn layui-btn-sm" lay-event="del"><i class="layui-icon layui-icon-delete"></i></button>
    </div>
    </script>
	<div th:include="/shop/include::footer"></div>
	<script>
        var conditions = $('#form').serialize();
        conditions = decodeURIComponent(conditions, true);
		layui.use([ 'table' ], function() {
			var $ = layui.jquery;
			var table = layui.table;
			// 渲染表格
			var renderTable = function() {
				layer.load(2);
				table.render({
					elem : '#shop_member_address-table',
					url : '/shop/member_address/list',
					toolbar : '#toolbarShopMemberAddress',
					page : true,
					id : 'shopMemberAddressReload',
                    where : {"conditions":conditions},
					cols : [ [ {
						type : 'checkbox',
						fixed : 'left'
					}, 
					{
						unresize : true,
						sort : true,
						width : 80,
						align : 'center',
					    field : 'id',
						title : 'id',
					 
					}, 
 					{
						align : 'center',
					    field : 'memberId',
						title : '会员ID',
					 
					}, 
 					{
						align : 'center',
					    field : 'province',
						title : '省',
					 
					}, 
 					{
						align : 'center',
					    field : 'city',
						title : '市',
					 
					}, 
 					{
						align : 'center',
					    field : 'area',
						title : '区',
					 
					}, 
 					{
						align : 'center',
					    field : 'address',
						title : '详细地址',
					 
					}, 
 					{
						align : 'center',
					    field : 'postalCode',
						title : '邮政编码',
					 
					}, 
 					{
						align : 'center',
					    field : 'receivingName',
						title : '收货人',
					 
					}, 
 					{
						align : 'center',
					    field : 'receivingPhone',
						title : '电话号码',
					 
					}, 
 					{
						align : 'center',
					    field : 'isDefault',
						title : '是否默认 0：不默认1：默认',
					 
					}, 
 					{
						align : 'center',
					    field : 'createTime',
						title : '添加时间',
					 
					}, 
 					{
						align : 'center',
					    field : 'updateTime',
						title : '修改时间',
					 
					}, 
 					{
						align : 'center',
					    field : 'enableState',
						title : '启用状态 0：已启用1：未启用',
					 
					}, 
 					{
						align : 'center',
					    field : 'deleteFlag',
						title : '删除状态 0：未删除1：已删除',
					 
					}, 
 					{
						title : '操作',
						toolbar : '#shop_member_address-state',
						align : 'center'
					} ] ],
					done : function() {
						layer.closeAll('loading');
					}
				});

			};
			renderTable();
			// 搜索 
			var active = {
				reload : function() {
					//执行重载
					table.reload('shopMemberAddressReload', {
						page : {
							curr : 1
						//重新从第 1 页开始
						},
						where : {

						}
					});
				}
			};

			$('#search').on('click', function() {
				var type = $(this).data('type');
				active[type] ? active[type].call(this) : '';
			});

			//头工具栏事件
			table.on('toolbar(shop_member_address-table)', function(obj) {
				var checkStatus = table.checkStatus(obj.config.id);
				switch (obj.event) {
				case 'add'://增加
					openAdd();
					break;
				case 'batchRemove'://批量删除
					var data = checkStatus.data;
					if (data.length < 1) {
						layer.msg('请至少选择一个');
						break;
					}
					//批量删除
					batchRemove(data);
				}
			});

			//监听工具条
			table.on('tool(shop_member_address-table)', function(obj) {
				var data = obj.data;
				var layEvent = obj.event;
				if (layEvent === 'del') {//删除
					remove(data.id);
				} else if (layEvent === 'edit') {//修改
					edit(data.id);
				}
			});

			function remove(id) {
				layer.confirm('确定要删除选中的记录？', {
					btn : [ '确定', '取消' ]
				}, function() {
					//删除
					ajaxPostLoad('/shop/member_address/remove', {
						id : id
					});
				})
			}

			function batchRemove(data) {
				layer.confirm("确认要删除选中的'" + data.length + "'条数据吗?", {
					btn : [ '确定', '取消' ]
				}, function() {
					var ids = new Array();
					$.each(data, function(i, row) {
						ids[i] = row['id'];
					});
					console.log("remove->ids:" + ids);
					//批量删除
					ajaxPostLoad('/shop/member_address/batchRemove', {
						ids : ids
					});
				});
			}

			function edit(id) {
				layer.open({
					type : 2,
					title : '修改',
					maxmin : true,
					shadeClose : false, // 点击遮罩关闭层
					area : [ '60%', '100%' ],
					content : '/shop/member_address/edit/' + id // iframe的url
				});
			}

			function openAdd() {
				layer.open({
					type : 2,
					title : '增加',
					maxmin : true,
					shadeClose : false, // 点击遮罩关闭层
					area : [ '60%', '100%' ],
					content : '/shop/member_address/add' // iframe的url
				});
			}
		});
	</script>
</body>
</html>